package com.letoken.platform.app.controller;

import com.letoken.platform.app.service.*;
import com.letoken.platform.pub.annotation.pub.Trim;
import com.letoken.platform.pub.enums.LetokenApiResponseEnum;
import com.letoken.platform.pub.enums.LetokenTokenTypeEnum;
import com.letoken.platform.pub.exception.ApiServiceException;
import com.letoken.platform.pub.req.PageData;
import com.letoken.platform.pub.req.QueryReqBase;
import com.letoken.platform.pub.res.ApiResponse;
import com.letoken.platform.repo.app.po.AppUserIssueRecord;
import com.letoken.platform.repo.app.req.team.AppBindInvitationCodeReq;
import com.letoken.platform.repo.app.req.token.WithdrawLetReq;
import com.letoken.platform.repo.app.res.config.QueryAppIssueConfigRes;
import com.letoken.platform.repo.app.res.config.QueryLetokenHistoryRes;
import com.letoken.platform.repo.app.res.team.AppBindInvitationCodeRes;
import com.letoken.platform.repo.app.res.token.WaitCirculationRes;
import com.letoken.platform.repo.utlis.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author letokenlabs
 * @date 2022/12/3$
 */
@RestController
@RequestMapping("/letoken")
@Api(tags = "Le账户-Le代币")
public class AppLeTokenController {

    @Autowired
    private AppConfigService appConfigService;

    @Resource
    private AppLeTokenService appLeTokenService;

    @Resource
    private AppUserIssueRecordService appUserIssueRecordService;

    @Autowired
    private AppUserIssueHistoryService appUserIssueHistoryService;


    @Trim
    @PostMapping("/withdraw")
    @ApiOperation(value = "提现", notes = "Letoken提现(站内转账)")
    public ApiResponse tokenWithdraw(@Validated @RequestBody WithdrawLetReq req) {
        appLeTokenService.tokenWithdraw(req);
        return ApiResponse.create();
    }

    @Trim
    @GetMapping("/issue/config")
    @ApiOperation(value = "铸币发行-查询铸币流通配置", notes = "查询铸币流通配置")
    public ApiResponse<QueryAppIssueConfigRes> queryLetokenIssueConfig() {
        return ApiResponse.create(appConfigService.queryLetokenIssueConfig());
    }

    @GetMapping("/circulation")
    @ApiOperation(value = "铸币发行-待流通-查询待流通", notes = "查询待流通数量")
    public ApiResponse<BigDecimal> queryLetokenCirculation() {
        return ApiResponse.create(appConfigService.queryLetokenCirculation());
    }


    @GetMapping("/coinage_issuance/pending_circulation")
    @ApiOperation(value = "铸币发行-待流通-查询待流通", notes = "查询待流通数量")
    public ApiResponse<BigDecimal> coinageIssuancePendingCirculation() {
        return ApiResponse.create(appConfigService.coinageIssuancePendingCirculation());
    }

    @Trim
    @PostMapping("/history")
    @ApiOperation(value = "铸币发行-历史记录", notes = "铸币发行-历史记录")
    public ApiResponse<PageData<QueryLetokenHistoryRes>> queryLetokenHistoryPage(@RequestBody @Validated QueryReqBase req) {
        return ApiResponse.create(appUserIssueHistoryService.queryLetokenHistoryPage(req));
    }

    @GetMapping("/waitCirculation")
    @ApiOperation(value = "铸币发行-查询周期流通量", notes = "铸币发行-查询周期流通量")
    public ApiResponse<PageData<WaitCirculationRes>> queryWaitCirculation() {
        Integer userId = WebUtils.getUserId();
        return ApiResponse.create(appUserIssueRecordService.queryWaitCirculation(userId));
    }

}
